<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" />
<link type="text/css"
	href="${pageContext.request.contextPath}/themes/icon.css"
	rel="stylesheet">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
$(function(){	
	$('#dg').datagrid({    
	    url:'TempOrder',

	    columns:[[  

	      	{field:'ck',checkbox:true,width:50,}, 
			{field:'pId',title:'商品ID',width:100,hidden:true},
			{field:'pName',title:'商品名',width:150,}, 
			{field:'pType',title:'商品型号',width:150,},    
			{field:'pPrice',title:'商品单价（元）',width:100,}, 
			{field:'poAmount',title:'商品成交量',width:100}, 
			{field:'eSum',title:'单项总价（元）',width:100},       
			    
	    ]],	
	    pagination:true,
	    pageList:[5,10,20,30,50,100,200],
	    rownumbers:true,
	    //编辑按钮
	    toolbar: [{
	    	//录入交易信息
			iconCls: 'icon-add',
			text:'增加商品交易',
			handler: function(){
				$("#create").window('open');			
			}
		},'-',{
			//删除交易信息
			iconCls: 'icon-remove',
			text:'除去商品交易',
			handler: function(){
				var sel = $('#dg').datagrid('getSelections');
				var ids = [];
				$.each(sel, function(i, n) {
					ids.push(n.pId);					
				})
				if (sel.length == 0) {
					$.messager.alert('提示', '请选择想要删除的对象');
				} else {
					$.ajax({
						url : 'DelTempPro',
						traditional:true,
						type : 'post',
						data : {"ids" : ids},
						dataTpye : 'json',
						success : function(flag) {
							if(flag==0){
								$.messager.alert('提示', '删除失败');
							}else{
								$('#dg').datagrid('reload');
							}
						}
					})
				}			
			}
		},'-',{
			//修改交易量
			iconCls: 'icon-edit',
			text:'更改商品交易数量',
			handler: function(){
				var sel = $('#dg').datagrid('getSelections');
				if(sel.length == 1){
					$("#update").window('open'); 	
					var sv = sel[0].poAmount;
					$("#pAmountud").numberbox('setValue',sv);
				}else{
					$.messager.alert('提示','请仅选择一条信息进行修改'); 
				}					
			}
		}],
		onLoadSuccess:function(){
			//合计
			var data = $('#dg').datagrid('getData').rows;
			var sum = 0;
			$.each(data,function(i,n){
				sum += n.eSum;
			})
			$("#sum").numberbox('setValue',sum);	
		}
	})
	//录入信息确认按钮
	$("#confirm").linkbutton({
		width : 50,
		height : 30,
		onClick : function() {
			var pId = $("#pId").textbox('getText');
			var pAmount = $("#pAmount").textbox('getText');				
			$.ajax({
				url:'InsertTempOrder',
				data:{'pId':pId,'pAmount':pAmount},
				type:'post',
				success:function(flag){
					if("-1" == flag){
						$.messager.alert('提示','数据录入失败');  						
					}else{
						$("#pId").textbox('clear');
						$("#pAmount").textbox('clear');
						$("#create").window('close');	
						$('#dg').datagrid('reload');
											
					}
				}
			})
		}
	});
	//录入信息取消按钮
	$("#reset").linkbutton({
		width : 50,
		height : 30,
		onClick :function(){
			$("#pId").textbox('clear');
			$("#pAmount").textbox('clear');
			$("#create").window('close');
		}
	});
	//修改交易量确认按钮
	$("#confirmud").linkbutton({
		width : 50,
		height : 30,
		onClick : function() {
			var sel = $('#dg').datagrid('getSelections');		
			$.ajax({
				url:'UpdTempPro',
				data:{"ptAmountud":$("#pAmountud").val(),"ptIdud":sel[0].pId},
				type:'post',
				success:function(flag){
					$('#dg').datagrid('reload');
					if(flag == 1){
						$("#update").window('close');
					}else{
						$.messager.alert('提示','数量修改失败'); 
					}
					
				}
			})		
		}
	});
	//修改交易量取消按钮
	$("#resetud").linkbutton({
		width : 50,
		height : 30,
		onClick :function(){		
			$("#update").window('close');
		}
	});
	

	
})
</script>
<body>
	<table id="dg">	</table>

	<div style="margin-top: 20px"> 
	总价<input type='text' id ='sum' class='easyui-numberbox'  data-options='min:0,precision:2' style='height: 25px;width: 100px'/>
	</div>


	<!-- 增加商品信息 -->
	<div id="create" class="easyui-window" title="录入商品信息" style="width:300px;height:200px" data-options="closed:true">
		<div style="margin: 20px">
		商品ID<input id="pId" type="text" class="easyui-numberbox"/><br/></br>
		交易量<input id="pAmount" type="text" class="easyui-numberbox"/><br/></br>
		<!-- 按钮 -->
		<a id="confirm" href="#" class="easyui-linkbutton" style="margin-left: 50px">确定</a>  
		<a id="reset" href="#" class="easyui-linkbutton" style="margin-left: 20px">取消</a>  
		</div>
	</div>  
	<!-- 修改商品交易量 -->
	<div id="update" class="easyui-window" title="修改交易量" style="width:300px;height:200px" data-options="closed:true">
		<div style="margin: 20px">	
		交易量<input id="pAmountud" type="text" class="easyui-numberbox"/><br/></br>
		<!-- 按钮 -->
		<a id="confirmud" href="#" class="easyui-linkbutton" style="margin-left: 50px">确定</a>  
		<a id="resetud" href="#" class="easyui-linkbutton" style="margin-left: 20px">取消</a>  
		</div>
	</div>  
	
</body>
</html>